package com.atues.c2l;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Main {

    public static void list2Array() {
        String [] s= new String[]{
                "dog", "lazy", "a", "over", "jumps", "fox", "brown", "quick", "A"
        };
        List<String> list = Arrays.asList(s);
        Collections.reverse(list);
        System.out.println(list);
        //没有指定类型的话会报错
        s=list.toArray(new String[0]);
        System.out.println(s);
    }
    public static void main(String[] args) {
//        List myList = Arrays.asList(1, 2, 3);
//        System.out.println(myList.getClass());
//        myList.add(4);//运行时报错：UnsupportedOperationException
//        myList.remove(1);//运行时报错：UnsupportedOperationException
//        myList.clear();//运行时报错：UnsupportedOperationException
        list2Array();

        int[] myArray = {1, 2, 3};
        List myList = Arrays.asList(myArray);
        System.out.println(myList.size());//1
        System.out.println(myList.get(0));//数组地址值
        System.out.println(myList.get(1));//报错：ArrayIndexOutOfBoundsException
        int[] array = (int[]) myList.get(0);
        System.out.println(array[0]);//1
    }
}
